package com.martin.fastframe.ui.danmu

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.martin.fastframe.R
import com.martin.fastframe.databinding.ActivityDanmuBinding
import com.martin.fastframe.ui.binding.adapter.BindingAdapterViewModel
import com.martin.lib_base.base.BaseActivity
import com.martin.lib_base.impl.EmptyViewModel
import dev.utils.common.RandomUtils

/**
 * 弹幕功能
 */
class DanMuActivity : BaseActivity<ActivityDanmuBinding,EmptyViewModel>() {

    private val danMuModel by lazy {
        DanMuModel(binding.fl, 3)
    }

    override fun getViewModelClass() = EmptyViewModel::class.java

    override fun layoutId() = R.layout.activity_danmu

    override fun initOnCreate(savedInstanceState: Bundle?) {

        binding.btn.setOnClickListener {
            val text = binding.et.text ?: RandomUtils.getRandomLetters(10)
            danMuModel.offer(
                createDanMuItem(text.toString())
            )
        }
    }

    private fun createDanMuItem(message: String): BaseDanMuItem {
        return if (RandomUtils.getRandom(5) % 2 == 0) {
            MessageDanMuItem(
                RandomUtils.getRandomCapitalLetters(6) + "：",
                message
            )
        } else {
            GiftDanMuItem(
                message,
                "https://img2.woyaogexing.com/2022/12/13/5789460f70915b962b2ac2247c0d156f.jpg"
            )
        }
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, DanMuActivity::class.java)
            context.startActivity(starter)
        }
    }
}